﻿using AmiDraw.Editor.Model;
using AmiDraw.Lib;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AmiDraw.Lib.Models;

namespace AmiDraw.Editor.Factory
{
    public class ObservableFactory
    {
        public static ObservableCard GetObservableCard(AcCard card)
        {
            return new ObservableCard
            {
                Name = card.Name,
                ScriptResKey = card.ScriptResKey,
                Description = card.Description,
                ImageResKey = card.ImageResKey,
                ExtraProbability = card.ExtraProbability
            };
        }

        public static AcCard GetAcCard(ObservableCard card)
        {
            return new AcCard
            {
                Name = card.Name,
                ScriptResKey = card.ScriptResKey,
                Description = card.Description,
                ImageResKey = card.ImageResKey,
                ExtraProbability = card.ExtraProbability
            };
        }


        public static AcLevel GetAcLevel(ObservableLevel level)
        {
            return new AcLevel
            {
                Name = level.Name,
                Ratio = level.Ratio,
                //将ObservableCards重新转换为Cards
                Cards = level.Cards.Select(x => GetAcCard(x)).ToList()
            };
        }

        /// <summary>
        /// 将ObservableLevel集合转换成可保存的
        /// </summary>
        /// <param name="observableCollection"></param>
        /// <returns></returns>
        public static List<AcLevel> GetAcLevels(ObservableCollection<ObservableLevel> observableCollection)
        {
            return observableCollection.Select(x => ObservableFactory.GetAcLevel(x)).ToList();
        }
    }
}
